package movie.service.impl;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import movie.entity.Film;
import movie.mapper.FilmMapper;
import movie.service.FilmService;
@Service
public class FilmServiceImpl implements FilmService {
	@Autowired
	private FilmMapper filmMapper;
	@Override
	public Film find_film_by_id(int id) {
		
		return filmMapper.findByMovieId(id);
	}
	
	@Override
	public List<Film> find_home_reying(){
		return filmMapper.findReYing().subList(0, 8);
	}
	
	@Override
	public List<Film> find_home_willshow(){
		return filmMapper.findWillShow().subList(0, 8);
	}
	
	@Override
	public List<Film> find_home_showed(){
		return filmMapper.findShowed().subList(0, 10);
	}
	
	@Override
	public List<Film> find_home_piaofang(){
		List<Film> l = filmMapper.findReYing();
        class FilmComparetor1 implements Comparator<Film> {
            @Override
            public int compare(Film h1, Film h2) {
                return h2.getintpf() - h1.getintpf();
            }
        }
        Collections.sort(l, new FilmComparetor1());
        List<Film> f = l.subList(0, 8);
		return f;
	}
	
	@Override
	public List<Film> find_home_wantsee(){
		List<Film> l = filmMapper.findWillShow();
        class FilmComparetor2 implements Comparator<Film> {
            @Override
            public int compare(Film h1, Film h2) {
                return h2.getWantsee() - h1.getWantsee();
            }
        }
        Collections.sort(l, new FilmComparetor2());
        List<Film> f = l.subList(0, 8);
		return f;
	}
	
	@Override
	public int updatewantsee(Film film) {
		return filmMapper.updateWantsee(film);
	}
	
	@Override
	public int updatescore(Film film) {
		return filmMapper.updateScore(film);
	}
	
	@Override
	public List<Film> findbyname(String name) {
		return filmMapper.findByFilmName(name);
	}
}
